package com.adcc.ags.cgw.entity.msg;

import com.adcc.ags.cgw.entity.BaseEntity;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.base.Optional;
import com.google.common.base.Strings;

/**
 * 核心网关入库消息实体
 */
public class TrafficMsg extends BaseEntity {

    // id
    private String id = Strings.nullToEmpty("");

    // 类型
    private String type = Strings.nullToEmpty("");

    // 发送者
    private String sender = Strings.nullToEmpty("");

    // 接收者
    private String receiver = Strings.nullToEmpty("");

    // 报文原文
    private String rawMsg = Strings.nullToEmpty("");

    // 状态
    private String state = "F";

    // 异常用户
    private String errorUser = Strings.nullToEmpty("");

    // 异常代码
    private String errorCode = Strings.nullToEmpty("");

    /**
     * 构造函数
     */
    public TrafficMsg(){

    }

    /**
     * 构造函数
     * @param cgwMsg
     */
    public TrafficMsg(CGWMsg cgwMsg){
        if(cgwMsg != null){
            id = cgwMsg.getId();
            type = cgwMsg.getType().toString();
            this.sender = cgwMsg.getSender();
            this.receiver = cgwMsg.getReceiver();
            byte[] buffer = cgwMsg.getContent().getContent();
            rawMsg = new String(buffer,0,buffer.length);
        }
    }

    /**
     * 构造函数
     * @param cgwMsg
     * @param state
     */
    public TrafficMsg(CGWMsg cgwMsg,String state){
        if(cgwMsg != null){
            id = cgwMsg.getId();
            type = cgwMsg.getType().toString();
            this.sender = cgwMsg.getSender();
            this.receiver = cgwMsg.getReceiver();
            byte[] buffer = cgwMsg.getContent().getContent();
            rawMsg = new String(buffer,0,buffer.length);
        }
        this.state = state;
    }


    /**
     * 构造函数
     * @param cgwMsg
     * @param state
     * @param errorUser
     * @param errorCode
     */
    public TrafficMsg(CGWMsg cgwMsg,String state,String errorUser,String errorCode){
        if(cgwMsg != null){
            id = cgwMsg.getId();
            type = cgwMsg.getType().toString();
            this.sender = cgwMsg.getSender();
            this.receiver = cgwMsg.getReceiver();
            byte[] buffer = cgwMsg.getContent().getContent();
            rawMsg = new String(buffer,0,buffer.length);
        }
        this.state = state;
        this.errorUser = errorUser;
        this.errorCode = errorCode;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getSender() {
        return sender;
    }

    public void setSender(String sender) {
        this.sender = sender;
    }

    public String getReceiver() {
        return receiver;
    }

    public void setReceiver(String receiver) {
        this.receiver = receiver;
    }

    public String getRawMsg() {
        return rawMsg;
    }

    public void setRawMsg(String rawMsg) {
        this.rawMsg = rawMsg;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getErrorUser() {
        return errorUser;
    }

    public void setErrorUser(String errorUser) {
        this.errorUser = errorUser;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    @Override
    public Optional<BaseEntity> formatJson(String json) throws Exception {
        return null;
    }

    @Override
    public String toJSON() throws JsonProcessingException {
        return null;
    }
}
